<%@ page import="java.sql.Statement" import="java.sql.ResultSet" import="java.sql.Connection" %>
<%@page import="connection.DBConnection"%>
<%@page import="java.util.*" %>
<%@page import="java.text.SimpleDateFormat" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Purchase voucher Report</title>
</head>
<body>
<h2 align="center"> Purchase Voucher Report</h2>

<form name="fr12" method="post">

  <%
        String exportToExcel = request.getParameter("exportToExcel");
        if (exportToExcel != null && exportToExcel.toString().equalsIgnoreCase("YES")) 
        {
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-Disposition", "inline; filename=" + "PurchaseVoucherReport.xls");
 
        }
    %>

<table border=1 align="center"> 

<tr>
	<th>Invoice Number</th>
	<th>Date</th>
	<th>Supplier Name</th>
	<th>Supplier Code</th>
	<th>Product Name</th>
	<th>Product Quantity</th>
	<th>Product Rate</th>
	<th>Net Amount</th>
	<th>Taxation Category</th>
	<th>Tax Amount</th>
	<th>Transport Charges</th>
	<th>Other Costs</th>
	<th>Total Amount</th>
	<th>Credit Limit</th>
</tr>

		<%  DBConnection dbc=new DBConnection();
			Connection con=dbc.getNewConnection();
			Statement st = null;
			ResultSet rs = null;
			
			double pvnet=0.0,pvtax=0.0,pvtransport=0.0,pvot=0.0,pvtotal=0.0;
			double pv8=0.0,pv10=0.0,pv11=0.0,pv12=0.0,pv13=0.0;
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select * from PurchaseVoucher2 where status=1"); %>
	        	
       		 <%  while(rs.next()){ %>
<tr>
					<td><%= rs.getString(1)%></td>
            		
            		<% String pvdate= rs.getString(2); 
           	    		 SimpleDateFormat fromsql = new SimpleDateFormat("yyyy-MM-dd");
        				 SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
        		 		 String newdate =formatter.format(fromsql.parse(pvdate));
            		%>
            		<td><%=newdate %></td>
            		
            		<td><%= rs.getString(3)%></td>
            		<td><%= rs.getString(4)%></td>
            		<td><%= rs.getString(5)%></td>
 					<td><%= rs.getDouble(6)%></td>
 					<td><%= rs.getDouble(7)%></td>  
 					
 					<%pv8=rs.getDouble(8); %>         		
            		<td><%=pv8 %></td>
            		<td><%= rs.getDouble(9)%></td>
            		
            		<%pv10=rs.getDouble(10); %>         		
            		<td><%=pv10 %></td>
            		         		
					<%pv11=rs.getDouble(11); %>         		
            		<td><%=pv11 %></td>
            		
            		<%pv12=rs.getDouble(12); %>         		
            		<td><%=pv12 %></td>
            		
            		<%pv13=rs.getDouble(13); %>         		
            		<td><%=pv13 %></td>
            		
            		
            		<td><%= rs.getInt(14)%></td>
            		
</tr>
        		<% 
	        		pvnet=pvnet+pv8;
    				pvtax=pvtax+pv10;
					pvtransport=pvtransport+pv11;
					pvot=pvot+pv12;
					pvtotal=pvtotal+pv13;
       		 		} %>
  
	 		<% }
			catch(Exception e){} %>
			
<tr>
	<td> <b> Total </b></td>
	<td> </td>
	<td> </td>
	<td> </td>
	<td> </td>
	<td> </td>
	<td> </td>
	<td> <%=pvnet %></td>
	<td> </td>
	<td> <%=pvtax %></td>
	<td> <%=pvtransport %></td>
	<td> <%=pvot%> </td>
	<td> <%=pvtotal %></td>
	<td> </td>
	
</tr>	
			
<!--
<tr> 
<td> ${user1.pvinno} </td> 
<td> ${user1.date} </td> 
<td> ${user1.pvsname} </td> 
<td> ${user1.pvscode} </td> 
<td> ${user1.pvstname} </td> 
<td> ${user1.pvqua} </td> 
<td> ${user1.pvrate} </td> 
<td> ${user1.pvneta} </td>
<td> ${user1.pvtaxcat} </td>  
<td> ${user1.pvtaxa} </td> 
<td> ${user1.pvtrans} </td> 
<td> ${user1.pvot} </td>
<td> ${user1.pvtota} </td> 
<td> ${user1.pvcreadlim} </td> 
</tr>
-->
			
</table><br><br> 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    <%
        if (exportToExcel == null) {
    %>
    <a href="PurchaseVoucherReport.jsp?exportToExcel=YES">Export to Excel</a>
    <%
        }
    %>
</form>

<br><br> 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<form name="delete_form" action="PurchaseVoucherDeleteServlet">
<input type="text" name="delete"> 
<input type="submit" value="Delete Voucher">

<br><br> 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	
<a href="http://localhost:8081/BOA_Web/DeletedPurchaseVouchers.jsp">Deleted Purchase Vouchers</a>


<center><input type="button" value="Print this page" onClick="window.print()"></center>

</form>


</body>
</html>